import api from "@/util/api";

async function findAll(pageNo = 1, pageSize = 10, params = {}) {
    let resp = await api({
        url: "/brand-api/api/v1/brand",
        method: "get",
        params: {
            pageNo,
            pageSize,
            ...params
        }
    });
    return resp.data || resp; 
}

async function deleteById(id){
    let resp = await api({
        url:"/brand-api/api/v1/brand/deleteById/" + id,
        method:"delete"
    });
    return resp;
}

async function save(brand){
    let resp = await api({
        url:"/brand-api/api/v1/brand/add",
        method:"post",
        data:brand
    });
    return resp;
}

async function update(brand)    {
    let resp = await api({
        url:"/brand-api/api/v1/brand/update",
        method:"put",
        data:brand
    });
    return resp;
}

async function updateStatus(id,status){
    let resp = await api({
        url:"/brand/status",
        method:"put",
        params:{
            id,
            status
        }
    });
    return resp;
}

async function deleteAll(ids){
    let resp = await api({
        url:"/brand-api/api/v1/brand/delete",
        method:"delete",
        params: { ids: ids },  // 改为使用 params 而不是 data
        paramsSerializer: {
            indexes: null // 确保数组参数格式为 ids=22&ids=23
        }
    });
    return resp;
}


export {findAll,deleteById,save,update,updateStatus,deleteAll};